//-----------------------------------------------------------------------
// <copyright file="ErrorMessageDemo.cs" company="NMock2">
//
//   http://www.sourceforge.net/projects/NMock2
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
// </copyright>
// This is the easiest way to ignore StyleCop rules on this file, even if we shouldn't use this tag:
// <auto-generated />
//-----------------------------------------------------------------------
namespace NMock2.AcceptanceTests
{
    using System;
    using NUnit.Framework;

    [TestFixture]
    public class ErrorMessageDemo : AcceptanceTestBase
    {
        public delegate void Action();

        public interface ISyntacticSugar
        {
            string Property { get; set; }
            string this[string s] { get; set; }
            int this[int i,string s] { get; set; }
            
            event Action Actions;
        }

        [TestFixtureSetUp]
        public void TestFixtureSetUp()
        {
            SkipVerificationForThisFixture();
        }

        [Test, ExpectedException(typeof(NMock2.Internal.ExpectationException))]
        public void VerifyFailure()
        {
            IHelloWorld helloWorld = (IHelloWorld)Mocks.NewMock(typeof(IHelloWorld));
            
            Expect.Once.On(helloWorld).Method("Hello").WithNoArguments();
            Expect.Between(2,4).On(helloWorld).Method("Ask").With("What color is the fish?")
                .Will(Return.Value("purple"));
            Expect.AtLeast(1).On(helloWorld).Method("Ask").With("How big is the fish?")
                .Will(Throw.Exception(new InvalidOperationException("stop asking about the fish!")));

            helloWorld.Hello();
            helloWorld.Ask("What color is the fish?");

            Mocks.VerifyAllExpectationsHaveBeenMet();
        }
        
        [Test, ExpectedException(typeof(NMock2.Internal.ExpectationException))]
        public void UnexpectedInvocation()
        {
            IHelloWorld helloWorld = (IHelloWorld)Mocks.NewMock(typeof(IHelloWorld));
            
            Expect.Once.On(helloWorld).Method("Hello").WithNoArguments();
            Expect.Between(2,4).On(helloWorld).Method("Ask").With("What color is the fish?")
                .Will(Return.Value("purple"));
            Expect.AtLeast(1).On(helloWorld).Method("Ask").With("How big is the fish?")
                .Will(Throw.Exception(new InvalidOperationException("stop asking about the fish!")));
            
            helloWorld.Hello();
            helloWorld.Ask("What color is the fish?");
            helloWorld.Ask("What color is the hippo?");
        }

        [Test, ExpectedException(typeof(NMock2.Internal.ExpectationException))]
        public void IndexerSet()
        {
			ISyntacticSugar sugar = (ISyntacticSugar)Mocks.NewNamedMock(typeof(ISyntacticSugar), "sugar");
            
            Expect.Once.On(sugar).Set[10,"goodbye"].To(12);
            
            sugar[10,"hello"] = 11;
        }

        [Test, ExpectedException(typeof(NMock2.Internal.ExpectationException))]
        public void EventAdd()
        {
			ISyntacticSugar sugar = (ISyntacticSugar)Mocks.NewNamedMock(typeof(ISyntacticSugar), "sugar");

			Expect.Once.On(sugar).EventRemove("Actions", NMock2.Is.Anything);

            sugar.Actions += new Action(DoAction);
        }
        
        private void DoAction()
        {
            throw new NotSupportedException();
        }
    }
}
